import { fetchList } from "../..";
import { vipOptions } from "../../dict";
import {
  defaultModalFormState,
  defaultModalLoading,
  defaultModalVisible,
} from "../../store";
import { fetchDataById } from "../../utils";

export default () => {
  const defineModalConfig = {
    zIndex: 1002,
    modalInstance: ref(null),
    loading: defaultModalLoading[4],
    visible: defaultModalVisible[4],
    maskClosable: true,
    title: ref($t("base.openMember")),
    formState: defaultModalFormState[4],
    on: {
      async finish(values: any) {
        const formState = defaultModalFormState[4];
        const loading = defaultModalLoading[4];
        try {
          loading.value = true;
          await userApi.updateVip({
            userId: formState.userId,
            member_type: formState.member_type,
          });
          message.success($t("base.openSuccess"));
          fetchList();
          loading.value = false;
          defaultModalVisible[4].value = false;
          fetchDataById({ uid: formState.userId });
        } catch (error: any) {
          loading.value = false;
          message.error(error.message);
        }
      },
    },

    modalList: [
      {
        label: getProxyT("table5"),
        name: "member_type",
        options: vipOptions,
        type: "select",
        model: "member_type",
        placeholder: getProxyT("placeholder46"),
        allowClear: true,
        help: computed(() => (
          <>
            <i class="fs10">{$t("placeholder56")}</i>
          </>
        )),
      },
    ],
  };
  return defineModalConfig;
};
